package com.leyou.item.client;

import com.leyou.common.dto.PageDTO;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description //TODO feign调用接口
 * @Param
 * @return
 */
@FeignClient("item-service")
public interface ItemClient {

    //根据id查询品牌
    @GetMapping("/brand/{id}")
    BrandDTO queryBrandById(@PathVariable("id")Long id);

    //根据id的查询商品分类
    @GetMapping("/category/{id}")
    CategoryDTO queryCategoryById(@PathVariable("id")Long id);

    //分页查询spu
    @GetMapping("/goods/spu/page")
    PageDTO<SpuDTO> querySpuByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows,
            @RequestParam(value = "saleable", required = false) Boolean saleable,
            @RequestParam(value = "categoryId", required = false) Long categoryId,
            @RequestParam(value = "brandId", required = false) Long brandId,
            @RequestParam(value = "id", required = false) Long id);

    //根据spuId查询spuDetail
    @GetMapping("/goods/spu/detail")
    SpuDetailDTO querySpuDetailById(@RequestParam("id")Long id);

    //根据spuID查询sku
    @GetMapping("/goods/sku/of/spu")
    List<SkuDTO> querySkuBySpuId(@RequestParam("id")Long id);

    //查询规格参数
    @GetMapping("/spec/params")
    List<SpecParamDTO> querySpecParams(
            @RequestParam(value = "groupId",required = false)Long groupId,
            @RequestParam(value = "categoryId",required = false)Long categoryId,
            @RequestParam(value = "searching",required = false)Boolean searching
    );

    //根据spuId查询spu的所有规格参数值
    @GetMapping("/goods/spec/value")
    List<SpecParamDTO> querySpecValues(
            @RequestParam("id")Long id,
            @RequestParam(value = "searching",required = false)Boolean searching
            );

    //根据分类id查询分类集合
    @GetMapping("/category/list")
    List<CategoryDTO> queryCategoryByIds(@RequestParam("ids")List<Long> idList);

    //根据品牌id查询分类集合
    @GetMapping("/brand/list")
    List<BrandDTO> queryBrandByIds(@RequestParam("ids")List<Long> idList);

    //根据id批量查询sku
    @GetMapping("/goods/sku/list")
    List<SkuDTO> querySkuByIds(@RequestParam("ids")List<Long> ids);

    //根据id查询商品
    @GetMapping("/goods/{id}")
    SpuDTO queryGoodsById(@PathVariable("id")Long id);

    /**
     * 根据id查询spu，不包含别的
     * @param id 商品id
     * @return spu
     */
    @GetMapping("/goods/spu/{id}")
    SpuDTO querySpuById(@PathVariable("id") Long id);
    //根据分类id查询规格组及组内参数
    @GetMapping("/spec/list")
    List<SpecGroupDTO> querySpecList(@RequestParam("id")Long id);
    //减库存
    @PutMapping("/goods/stock/minus")
    void deductStock(@RequestBody Map<Long ,Integer> cartMap);
    //加库存
    @PutMapping("/goods/stock/plus")
    void addStock(@RequestBody Map<Long,Integer> cartMap);
}


